package com.findfuture.demo.model;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.sql.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Yanggang
 * Date: 11-11-17
 * Time: 下午2:59
 * To change this template use File | Settings | File Templates.
 */
@javax.persistence.Table(name = "users")
@Entity
public class Users {
    private int id;

    @javax.persistence.Column(name = "id", nullable = false, insertable = true, updatable = true, length = 10, precision = 0)
    @Id
    @GeneratedValue(generator = "paymentableGenerator")
    @GenericGenerator(name = "paymentableGenerator", strategy = "native")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    private String userName;

    @javax.persistence.Column(name = "userName", nullable = false, insertable = true, updatable = true, length = 50, precision = 0)
    @Basic
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    private String password;

    @javax.persistence.Column(name = "password", nullable = false, insertable = true, updatable = true, length = 50, precision = 0)
    @Basic
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    private String nickName;

    @javax.persistence.Column(name = "nickName", nullable = false, insertable = true, updatable = true, length = 50, precision = 0)
    @Basic
    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    private String job;

    @javax.persistence.Column(name = "job", nullable = true, insertable = true, updatable = true, length = 50, precision = 0)
    @Basic
    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    private int sex;

    @javax.persistence.Column(name = "sex", nullable = true, insertable = true, updatable = true, length = 10, precision = 0)
    @Basic
    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    private Date joinDate;

    @javax.persistence.Column(name = "joinDate", nullable = true, insertable = true, updatable = true, length = 10, precision = 0)
    @Basic
    public Date getJoinDate() {
        return joinDate;
    }

    public void setJoinDate(Date joinDate) {
        this.joinDate = joinDate;
    }

    private int state;

    @javax.persistence.Column(name = "state", nullable = false, insertable = true, updatable = true, length = 10, precision = 0)
    @Basic
    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    private Date birthday;

    @javax.persistence.Column(name = "birthday", nullable = true, insertable = true, updatable = true, length = 10, precision = 0)
    @Basic
    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    private String idCard;

    @javax.persistence.Column(name = "idCard", nullable = true, insertable = true, updatable = true, length = 20, precision = 0)
    @Basic
    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    private String phone;

    @javax.persistence.Column(name = "phone", nullable = true, insertable = true, updatable = true, length = 20, precision = 0)
    @Basic
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    private String address;

    @javax.persistence.Column(name = "address", nullable = true, insertable = true, updatable = true, length = 50, precision = 0)
    @Basic
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    private List<Users> relationUser;

    @ManyToMany(targetEntity = Users.class,
            cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch = FetchType.LAZY
    )
    @JoinTable(name = "users_relation",
            joinColumns = {@JoinColumn(name = "userId")},
            inverseJoinColumns = {@JoinColumn(name = "relationId")}
    )
    public List<Users> getRelationUser() {
        return relationUser;
    }

    public void setRelationUser(List<Users> relationUser) {
        this.relationUser = relationUser;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Users user = (Users) o;

        if (id != user.id) return false;
        if (sex != user.sex) return false;
        if (state != user.state) return false;
        if (address != null ? !address.equals(user.address) : user.address != null) return false;
        if (birthday != null ? !birthday.equals(user.birthday) : user.birthday != null) return false;
        if (idCard != null ? !idCard.equals(user.idCard) : user.idCard != null) return false;
        if (job != null ? !job.equals(user.job) : user.job != null) return false;
        if (joinDate != null ? !joinDate.equals(user.joinDate) : user.joinDate != null) return false;
        if (nickName != null ? !nickName.equals(user.nickName) : user.nickName != null) return false;
        if (password != null ? !password.equals(user.password) : user.password != null) return false;
        if (phone != null ? !phone.equals(user.phone) : user.phone != null) return false;
        if (userName != null ? !userName.equals(user.userName) : user.userName != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (userName != null ? userName.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (nickName != null ? nickName.hashCode() : 0);
        result = 31 * result + (job != null ? job.hashCode() : 0);
        result = 31 * result + sex;
        result = 31 * result + (joinDate != null ? joinDate.hashCode() : 0);
        result = 31 * result + state;
        result = 31 * result + (birthday != null ? birthday.hashCode() : 0);
        result = 31 * result + (idCard != null ? idCard.hashCode() : 0);
        result = 31 * result + (phone != null ? phone.hashCode() : 0);
        result = 31 * result + (address != null ? address.hashCode() : 0);
        return result;
    }
}
